<?php
class ExportsController extends AppController {

	var $name = 'Exports';
	var $uses = array('Member');
	
	function index() {
		error_reporting(E_ERROR | E_WARNING | E_PARSE);
		   require 'Spreadsheet/Excel/Writer.php';
	     	$workbook = new Spreadsheet_Excel_Writer();
			$workbook->setVersion(8, 'utf-8');
			$worksheet1 = &$workbook->addWorksheet('worksheet 1');
			$worksheet1->setInputEncoding('UTF-8');		
			$header = &$workbook->addFormat();
			$header->setBold();
		   //$header->setBorder();	
			//$worksheet =& $workbook->addWorksheet();
			//$format_bold->setBorder();
			$worksheet1->write(0, 0, "Họ tên", $header);
			$worksheet1->write(0, 1, "Tài khoản đăng nhập", $header);
			$worksheet1->write(0, 2, "Mật khẩu", $header);
			$worksheet1->write(0, 3, "Số CMTND", $header);
			$worksheet1->write(0, 4, "Ngày sinh", $header);
			$worksheet1->write(0, 5, "Mã số thuế", $header);
			$worksheet1->write(0, 6, "Thỏa thuận thuế", $header);
			$worksheet1->write(0, 7, "Địa chỉ ", $header);
			$worksheet1->write(0, 8, "Email", $header);
			$worksheet1->write(0, 9, "Điện thoại", $header);
			$worksheet1->write(0, 10, "Yahoo", $header);
			$worksheet1->write(0, 11, "Skype", $header);			
			
			# start by opening a query string
			$date=date('Y-m-d');
			$listName=$this->Member->find('all',array('conditions'=>array('Member.created'=>$date),'order'=>'Member.id ASC'));
			//pr($listName);die;
			$i=1;
			foreach($listName as $value){
				$worksheet1->write($i, 0, $value['Member']['name'], $header);
				$worksheet1->write($i, 1, $value['Member']['user'], $header);
				$worksheet1->write($i, 2, $value['Member']['pass_login'], $header);
				$worksheet1->write($i, 3, $value['Member']['passport'], $header);
				$worksheet1->write($i, 4, $value['Member']['birthday'], $header); 	
				$worksheet1->write($i, 5, $value['Member']['tax_code'], $header);
				$worksheet1->write($i, 6, $value['Member']['deal'], $header);
				$worksheet1->write($i, 7, $value['Member']['add'], $header);
				$worksheet1->write($i, 8, $value['Member']['email'], $header);
				$worksheet1->write($i,9, $value['Member']['mobile'], $header);
				$worksheet1->write($i, 10, $value['Member']['yahoo'], $header);
				$worksheet1->write($i, 11,$value['Member']['skype'], $header);
				
				
				$i++;
			
			}
			/*while($row=mysql_fetch_assoc($result)){
			$worksheet->write($i, 0, "$row[name]");
			$worksheet->write($i, 1, "$row[address]");
			$worksheet->write($i, 2, "$row[phone]");
			$worksheet->write($i, 3, "$row[email]");
			$worksheet->write($i, 4, "$row[comments]");
			$i++;
			}*/
			$workbook->send('list.xls');
			$workbook->close();
										
		
		

	}

}
?>